all: help


## build@编译API服务(可交叉编译为sqlite3版本)。
#cd server && go build -tags sqlite3 -o go-admin main.go
.PHONY:build
build:
	@cd server && CGO_ENABLED=0 go build -o go-admin main.go


## migrate@迁移数据库。
.PHONY:migrate
migrate:
	@cd server && ./go-admin migrate -c=config/settings.yml


## doc@生成Swagger接口文档。
.PHONY:doc
doc:
	@cd server && swag init --parseDependency --parseDepth=6


## client@运行UI客户端。
.PHONY:client
client:
	@cd client && npm run dev


## server@运行API服务。
.PHONY:server
server:
	@cd ./server && go run main.go server -c=config/settings.yml


.PHONY: test
test:
	@cd server && go test -v ./... -cover


.PHONY: docker
docker:
	@cd server && docker build . -t go-admin:latest


## clean@清理编译、日志和缓存等数据。
.PHONY:clean
clean:
	@rm -rf ./server/go-admin
	@rm -rf ./server/temp


## commit <msg>@提交Git(格式:make commit msg=备注内容,msg为可选参数)。
.PHONY:commit
message:=$(if $(msg),$(msg),"Rebuilded at $$(date '+%Y年%m月%d日 %H时%M分%S秒')")
commit:
	@echo "\033[0;34mPush to remote...\033[0m"
	@git add .
	@git commit -m $(message)
	@echo "\033[0;31m 💿 Commit完毕\033[0m"


## push <msg>@提交并推送到Git仓库(格式:make push msg=备注内容,msg为可选参数)。
.PHONY:push
push:commit
	@git push #origin master
	@echo "\033[0;31m 📡 Push完毕\033[0m"


## help@查看make帮助。
.PHONY:help
help:Makefile
	@echo "Usage:\n  make [<command> [param]]"
	@echo
	@echo "Available Commands:"
	@sed -n "s/^##//p" $< | column -t -s '@' |grep --color=auto "^[[:space:]][a-z-]\+[[:space:]]"
	@echo
	@echo "For more to see https://makefiletutorial.com/"
